import openpyxl

# 导入excel
wb = openpyxl.load_workbook('test.xlsx')

# 选择worksheet
# print(wb.sheetnames)
index = wb.sheetnames
ws = wb[index[1]] # 或 ws = wb['用户信息.xlsx']
# print(ws)

# 获取数据
# print(ws['C2'].value)

# 获取所有行内容
# for row in ws.rows:
#     # print(row)
#     # for cell in row:
#     #     print(cell.value)
#     data = [cell.value for cell in row]
#     print(data)

# 获取行数和列数
# print(ws.max_row)
# print(ws.max_column)
# 迭代行
# for row in ws.iter_rows(min_row=2,min_col=1,max_row=ws.max_row,max_col=ws.max_column):
#     # print(row)
#     data = [cell.value for cell in row]
#     print(data)

# 列迭代
for column in ws.iter_cols(min_row=2,min_col=1,max_row=ws.max_row,max_col=ws.max_column):
    # print(column)
    data = [cell.value for cell in column]
    print(data)

wb.close()